package com.ttj.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ttj.domain.oracle.OrderRecDetail;
import com.ttj.mapper.oracle.OrderRecDetailMapper;
import com.ttj.service.OrderRecDetailService;
import com.ttj.vo.BaseRes;

@Service
public class OrderRecDetailServiceImple implements OrderRecDetailService {

	@Resource
	private OrderRecDetailMapper recDetailMapper;
	
	@Override
	public int createDetail(Long orderId,OrderRecDetail recDetail) {
		OrderRecDetail detail = new OrderRecDetail();
		detail.setOrderId(Integer.parseInt(String.valueOf(orderId)));
		detail.setId(recDetail.getGid());
		int uint = recDetail.getUint();
		if(uint==0){
			detail.setrNum(recDetail.getNum()*1000);
		}
		if(uint==1){
			detail.setrNum(recDetail.getNum());
		}
		double price = recDetail.getPer()*100;
		int per = (new Double(price)).intValue();
		detail.setPrice(per);//单价
		detail.setfPrice(recDetail.getTotal()*100);//单品总价
		return recDetailMapper.createDetail(detail);
	}

	@Override
	public BaseRes<List<OrderRecDetail>> detailList(Long orderId) {
		List<OrderRecDetail> detailList = recDetailMapper.detailList(orderId);
		BaseRes<List<OrderRecDetail>> res = new BaseRes<List<OrderRecDetail>>();
		res.setData(detailList);
		return res;
	}

}
